package com.abiao.shop.controller;

import com.abiao.shop.pojo.User;
import com.abiao.shop.result.Result;
import com.abiao.shop.service.GoodsService;
import com.abiao.shop.service.UserService;
import com.abiao.shop.vojo.GoodsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: GoodsController    商品模块控制类
 * @Author: AB
 * @Date: 2021-07-15
 * @Version:v1.0
 */
@Slf4j
@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    UserService userService;
    @Autowired
    GoodsService goodsService;

    //商品列表页面
    @RequestMapping("/to_list")
    public String toGoodsList(Model model, User user){
        model.addAttribute("user",user);
        List<GoodsVo> goodsVoList = goodsService.goodsVoList();
        model.addAttribute("goodsVoList",goodsVoList);
        return "goodsList";
    }

    //商品详情页面
    @RequestMapping("/to_detail/{goodsId}")
    @ResponseBody
    public Result<?> toGoodsDetail(Model model, User user,@PathVariable("goodsId") long goodsId){
        GoodsVo goodsVo = goodsService.getGoodsVoById(goodsId);
        return Result.success(goodsVo);
    }

}
